<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<script>
    function Deque(){
        this.data=[];
    }
    Deque.prototype={
        constructor:Deque,
        unshift: function (elm) {//从队首入队
            this.data.unshift(elm);
        },
        shift: function () {//从队首出队
            return this.data.shift();
        },
        push: function (elm) {//从队尾入队
            this.data.push(elm);
        },
        pop: function () {//从队尾出队
            return this.data.pop();
        },
        front: function () {//获取队首元素
            return this.data[0];
        },
        back: function () {//获取队尾元素
            return this.data[this.length-1];
        },
        clear: function () {//清空
            delete this.data;
            this.data=[];
        },
        isEmpty: function () {//是否为空
            return this.data.length==0?true:false;
        },
        toString: function () {//显示
            return this.data.join('\n');
        }
    }

    function isPalindrome(str){
        //正序读取字符串，从队首入队
        var de=new Deque();
        for(var i= 0,l=str.length;i<l;i++){
            de.unshift(str[i]);
        }
        //从队首出队，比较
        return str==de.data.join('');
    }

    console.log(isPalindrome('abcba'));
    console.log(isPalindrome('abcbab'));
    console.log(isPalindrome('112211'));
    console.log(isPalindrome('11221122'));
</script>
</body>
</html>